package com.euc.springbootframework.email;

import com.euc.springbootframework.util.PropertiesLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;

/**
 * Created by WUNE on 5/14/2018.
 */
@Configuration
public class EmailConfig {

    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        PropertiesLoader propertiesLoader = new PropertiesLoader("/email.properties");
        Properties properties = propertiesLoader.getProperties();
        mailSender.setHost(properties.getProperty("mail.smtp.host"));
        mailSender.setPort(Integer.valueOf(properties.getProperty("mail.smtp.port")));
        mailSender.setUsername(properties.getProperty("mail.smtp.username"));
        mailSender.setPassword(properties.getProperty("mail.smtp.password"));
        mailSender.setJavaMailProperties(properties);
        return mailSender;
    }
}
